package com.zb.kc.controller;


import com.zb.kc.commonutils.R;
import com.zb.kc.entity.EduChapter;
import com.zb.kc.entity.vo.ChapterVo;
import com.zb.kc.service.IEduChapterService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author wanggen
 * @since 2020-04-10
 */
@RestController
@RequestMapping("/eduservice/chapter")
public class EduChapterController {

    @Autowired
    private IEduChapterService chapterService;

    /**
     * 课程大纲展示，根据课程查询课程的大纲，包括章节和小节
     *
     * @param courseId
     * @return
     */
    @ApiOperation(value = "根据课程id查询课程大纲信息")
    @GetMapping("{courseId}")
    public R getChapterVo(@PathVariable("courseId") String courseId) {
        List<ChapterVo> list = chapterService.getChapterVideoByCourseId(courseId);
        return R.ok().data("allChapterVideo", list);
    }

    @ApiOperation(value = "添加章节的方法")
    @PostMapping
    public R addChapter(@RequestBody EduChapter eduChapter) {
        chapterService.save(eduChapter);
        return R.ok();
    }

    @ApiOperation(value = "根据章节id查询章节")
    @GetMapping("getChapter/{id}")
    public R getChapterById(@PathVariable("id") String id) {
        EduChapter chapter = chapterService.getById(id);
        return R.ok().data("chapter", chapter);
    }

    @ApiOperation(value = "修改章节的方法")
    @PutMapping
    public R updateChapter(@RequestBody EduChapter eduChapter) {
        chapterService.updateById(eduChapter);
        return R.ok();
    }

    @ApiOperation(value = "删除章节")
    @DeleteMapping("{id}")
    public R deleteChapterById(@PathVariable("id") String id) {
        chapterService.deleteChapter(id);
        return R.ok();
    }



}